var express = require('express');
var router = express.Router();
var query = require('./Database');
/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('ProOrder', {});
});
router.post('/orderall',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    console.log(list);
    let rows = await query("select goods.id,goods.cartname,goods.cartimgsrc,goods.cartversion,goods.cartcolor,goods.cartprice,goods.cartcount,goods.shopid,goods.state,goods.goodstime,shop.shopname from goods join shop  where goods.userid = "+ list.userid + " and goods.shopid = shop.id and goods.state<=10");
    // let goodsrows = await  query("select DISTINCT shopid,state,goodstime from goods");
    console.log('+++++++++++++++++++');
    console.log(rows);
    console.log('+++++++++++++++++++');
    let data = [{code:100},rows];
    res.send(data);
});
router.post('/orderone',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    console.log(list);
    let rows = await query("select goods.id,goods.cartname,goods.cartimgsrc,goods.cartversion,goods.cartcolor,goods.cartprice,goods.cartcount,goods.shopid,goods.state,goods.goodstime,shop.shopname from goods join shop  where goods.userid = "+ list.userid + " and goods.shopid = shop.id and goods.state="+list.state);
    // let goodsrows = await  query("select DISTINCT shopid,state,goodstime from goods");
    console.log('+++++++++++++++++++');
    console.log(rows);
    console.log('+++++++++++++++++++');
    let data = [{code:100},rows];
    res.send(data);
});
router.post('/ordertwo',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    console.log(list);
    let rows = await query("select goods.id,goods.cartname,goods.cartimgsrc,goods.cartversion,goods.cartcolor,goods.cartprice,goods.cartcount,goods.shopid,goods.state,goods.goodstime,shop.shopname from goods join shop  where goods.userid = "+ list.userid + " and goods.shopid = shop.id and goods.state = 1 or state = 10");
    // let goodsrows = await  query("select DISTINCT shopid,state,goodstime from goods");
    console.log('+++++++++++++++++++');
    console.log(rows);
    console.log('+++++++++++++++++++');
    let data = [{code:100},rows];
    res.send(data);
});
router.post('/orderrefund',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    console.log(list);
    let rows = await query("select goods.id,goods.cartname,goods.cartimgsrc,goods.cartversion,goods.cartcolor,goods.cartprice,goods.cartcount,goods.shopid,goods.state,goods.goodstime,shop.shopname from goods join shop  where goods.userid = "+ list.userid + " and goods.shopid = shop.id and goods.state = 7 or state = 8 or state = 9");
    // let goodsrows = await  query("select DISTINCT shopid,state,goodstime from goods");
    console.log('+++++++++++++++++++');
    console.log(rows);
    console.log('+++++++++++++++++++');
    let data = [{code:100},rows];
    res.send(data);
});
router.post('/change',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    console.log('--------------');
    console.log(list);
    await query("update goods set state ="+list.state+",goodstime ="+list.goodstime+ " where id = "+list.id);
    // let goodsrows = await  query("select DISTINCT shopid,state,goodstime from goods");
    console.log('+++++++++++++++++++');
    console.log('+++++++++++++++++++');
    let data = [{code:100}];
    res.send(data);
});
module.exports = router;